﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for VersionPublishManager
/// </summary>
public class VersionPublishManager
{
	public VersionPublishManager()
	{
		//
		// TODO: Add constructor logic here
		//
	}

    public String[] GetLastestVersion(String DomainID,String DepartmentID, String Employee_Code, String PlatformCode, String VersionCode)
    {
        String SQL = String.Format(@"select * from(
        select t1.versionname,t1.filename from version t1
        inner join versionpublish t2 on t1.versionid = t2.versionid and  t1.platform='{0}'
        and t1.versionname>'{1}' and t2.USERCODE='{2}' and t1.IsActive='1'
        union
        select t1.versionname,t1.filename from version t1
        inner join versionpublish t2 on t1.versionid = t2.versionid and  t1.platform='{0}'
        and t1.versionname>'{1}' and t2.DEPTCODE='{3}' and t1.IsActive='1' 
        union
        select t1.versionname,t1.filename from version t1
        inner join versionpublish t2 on t1.versionid = t2.versionid and  t1.platform='{0}'
        and t1.versionname>'{1}' and t2.DOMAINID='{4}' and t1.IsActive='1') a order by versionname desc
       
        ", PlatformCode, VersionCode, Employee_Code, DepartmentID, DomainID);

        var table= Jumpton.Data.SqlData.OpenSql(SQL).Tables[0];
       
        if (table.Rows.Count > 0)
        {
            String[] values = new String[] { table.Rows[0][0].ToString(), table.Rows[0][1].ToString() };
            return values;
        }
        return null;
    }

}